#include <stdio.h>

#include <unistd.h>

#include "ohos_init.h"
#include "cmsis_os2.h"
#include "iot_gpio.h"

#include "mlx90614.h"

#define MLX90614_INTERVAL_TIME_US 300000
#define MLX90614_TASK_STACK_SIZE 10240
#define MLX90614_TASK_PRIO 25

static void *MLX90614Task(const char *arg)
{
    float temp=0.0;
    (void)arg;
    while (1) {
		usleep(100000);
		temp=SMBus_ReadTemp();
		printf("温度值为：%.2f\r\n",temp);
    }
    return NULL;
}

static void MLX90614ExampleEntry(void)
{
    osThreadAttr_t attr;
    attr.name = "MLX90614Task";
    attr.attr_bits = 0U;
    attr.cb_mem = NULL;
    attr.cb_size = 0U;
    attr.stack_mem = NULL;
    attr.stack_size = MLX90614_TASK_STACK_SIZE;
    attr.priority = MLX90614_TASK_PRIO;

    if (osThreadNew((osThreadFunc_t)MLX90614Task, NULL, &attr) == NULL) {
        printf("[MLX90614Example] Falied to create MLX90614Task!\n");
    }
}

SYS_RUN(MLX90614ExampleEntry);